//
// Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
//
// GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
//  Author: Shawn.Tan
//  Date : 2025.10.28
//
//  History : Initial Version 2025.10.28
//
//
#include "PeStateUpdate.h"

#include <sstream>

#include "GenRequest.h"
#include "Log.h"

using namespace std;

/*!
  \file PeStateUpdate.cc
  \brief Code for updaing PE state
*/

namespace Green {

  PeStateUpdate::PeStateUpdate() : mRequestList()
  {
  }

  PeStateUpdate::PeStateUpdate(const PeStateUpdate& rOther)
    : Object(rOther), mRequestList()
  {
  }

  PeStateUpdate::~PeStateUpdate()
  {
    // Note: mRequestList contains a list GenRequest* which should be cleared by GenAgent!
  }

  Object* PeStateUpdate::Clone() const
  {
    return new PeStateUpdate(*this);
  }

  const std::string PeStateUpdate::ToString() const
  {
    stringstream out_stream;
    for (auto item_ptr : mRequestList) {
      out_stream << item_ptr->ToString() << endl;
    }

    return out_stream.str();
  }

  void PeStateUpdate::AddRequest(GenRequest* request)
  {
    mRequestList.push_back(request);
  }

  void PeStateUpdate::UpdateState(const std::string& stateName, const std::string& actionName, uint64 value)
  {
    GenStateRequest* gen_req = GenStateRequest::GenStateRequestInstance(stateName);
    gen_req->SetAction(actionName);
    gen_req->SetPrimaryValue(value);
    AddRequest(gen_req);
  }

  void PeStateUpdate::UpdateRegisterField(const std::string& regName, const std::string& fieldName, uint64 value)
  {
    GenRequest* register_req = GenSequenceRequest::GenSequenceRequestInstance("UpdateRegisterField");
    register_req->AddDetail("RegName", regName);
    register_req->AddDetail("FieldName", fieldName);
    register_req->AddDetail("FieldValue", value);
    AddRequest(register_req);
  }

}
